import store from '@/store'
import { createRouter, createWebHashHistory } from 'vue-router'
import routes from './routes'

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

router.beforeEach((to, from) => {
  if (to.meta.required && !store.state.user) {
    return {
      path: '/user/login',
      query: { redirect: to.fullPath }
    }
  }
})

export default router
